<%@ page import="projetjee.User"%>
<%@ page import="java.util.*"%>
<%--
LA PAGE DE VOTE
--%>

<!doctype html>
<html>
<head>
<meta name="layout" content="main">
<title>Voter !</title>
<style type="text/css" media="screen">
#status {
	background-color: #FFFFFF;
	border: .2em solid #132159;
	margin: 2em 2em 1em;
	padding: 1em;
	width: 20em;
	float: left;
	-moz-box-shadow: 0px 0px 1.25em #ccc;
	-webkit-box-shadow: 0px 0px 1.25em #ccc;
	box-shadow: 0px 0px 1.25em #ccc;
	-moz-border-radius: 0.6em;
	-webkit-border-radius: 0.6em;
	border-radius: 0.6em;
}

#statusRight {
	background-color: #FFFFFF;
	border: .2em solid #132159;
	margin: 2em 2em 1em;
	padding: 1em;
	width: 20em;
	float: right;
	-moz-box-shadow: 0px 0px 1.25em #ccc;
	-webkit-box-shadow: 0px 0px 1.25em #ccc;
	box-shadow: 0px 0px 1.25em #ccc;
	-moz-border-radius: 0.6em;
	-webkit-border-radius: 0.6em;
	border-radius: 0.6em;
}


.ie6 #status {
	display: inline;
	/* float double margin fix http://www.positioniseverything.net/explorer/doubled-margin.html */
}

#status ul {
	font-size: 0.9em;
	list-style-type: none;
	margin-bottom: 0.6em;
	padding: 0;
}

#status li {
	line-height: 1.3;
}

#status h1 {
	text-transform: uppercase;
	font-size: 1.1em;
	margin: 0 0 0.3em;
}

#page-body {
	margin: 2em 1em 1.25em 18em;
}

h2 {
	
	margin-top: 1em;
	margin-bottom: 0.3em;
	font-size: 1em;
	color: #720A0A;
}

p {
	line-height: 1.5;
	margin: 0.25em 0;
}

#controller-list ul {
	list-style-position: inside;
}

#controller-list li {
	line-height: 1.3;
	list-style-position: inside;
	margin: 0.25em 0;
}

@media screen and (max-width: 480px) {
	#status {
		display: none;
	}
	#page-body {
		margin: 0 1em 1em;
	}
	#page-body h1 {
		margin-top: 0;
	}
}
</style>
</head>
<body>
	<a href="#show-user" class="skip" tabindex="-1">
			<g:message code="default.link.skip.label" default="Skip to content&hellip;"/>
	</a>
	<div class="nav" role="navigation">
		<ul>
			<li>
				<a class="home" href="${createLink(uri: '/')}">
					<g:message code="default.home.label"/>
				</a>
			</li>
			<li>
				<g:link class="list" href="${createLink(uri: '/')}">Retour</g:link>
			</li>
			<%--<li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>--%>
		</ul>
	</div>
	<g:set var="userNow" value="${User.findByUsername(sec.loggedInUserInfo(field:'username'))}"/>
	<%
		/*portion de groovy*/
/*on récupere la liste des utilisateurs*/

		def userList = User.list()
		
		
		int lower = 0;
		int higher = userList.size();
		
		int id1
		def user1 = userNow
		while(user1 == userNow){
			/*on genere aléatoirement un entier entre 1 et le nombre d utilisateurs en faisant attention a etre different de l useur actuel*/
			id1 = (int)(Math.random() * (higher-lower)) + lower;
			
			/*on prend l user dans la liste*/
			user1 = userList[id1]
		}
		/*idem*/
		int id2
		def user2 = user1
		while(user2 == user1 || user2 == userNow) {
			id2 = (int)(Math.random() * (higher-lower)) + lower;
			user2 = userList[id2]
		}
	%>
	
	
	<div  id="status" role="main">
		<h2 align="center"><% out.print(user1.toString()) %></h2>
		<p align="center">
		<%--
				récupérer la photo du membre
				--%>
			<%def lien = 'http://localhost:8080/projetJEE/user/showImage/' + user1.getId().toString() %>
			<img class="Photo" src=${lien} width="200"/>
		</p>
		<p align="center">
			Son Profil : <br />
			<%--
				redirection vers le profil
				--%>
			<g:link controller='user' action='showVote' id="${id1+1}">Ici</g:link>
			<br />
		</p>
		<p align="center">
			Pour voter : <br />
			<%--
				redirection vers le vote
				--%>
			<g:link controller='user' action='voter' id="${id1+1}" params="[ids:"${id2+1}"]"> voter</g:link>
			<br />
		</p>
		
	</div>
	<div id="statusRight" role="main">
		<h2 align="center"><% out.print(user2.toString()) %></h2>
		<p align="center">
			<%def lienD = 'http://localhost:8080/projetJEE/user/showImage/' + user2.getId().toString() %>
			<img class="Photo" src=${lienD} width="200"/>
		</p>
		<p align="center">
			Son profil :<br />
			<g:link controller='user' action='showVote' id="${id2+1}">Ici</g:link>
			<br />
		</p>
		<p align="center">
			Pour voter : <br />
			<g:link controller='user' action='voter' id="${id2+1}" params="[ids:"${id1+1}"]"> voter</g:link>
			<br />
		</p>
		
	</div>
</body>
</html>
